package com.zhang.apipassenger.service.impl;

import com.zhang.apipassenger.remote.ServicePassengerUserClient;
import com.zhang.apipassenger.service.UserService;
import com.zhang.internalcommon.constant.CommonStatusEnum;
import com.zhang.internalcommon.dto.ResponseResult;
import com.zhang.internalcommon.dto.TokenResult;
import com.zhang.internalcommon.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private ServicePassengerUserClient servicePassengerUserClient;

	@Override
	public ResponseResult getUserByAccessToken(String accessToken) {
		// 解析accessToken
		TokenResult tokenResult = JwtUtils.checkToken(accessToken);
		if (tokenResult == null) {
			return ResponseResult.fail(CommonStatusEnum.TOKEN_ERROR.getCode(),CommonStatusEnum.TOKEN_ERROR.getValue());
		}
		String phone = tokenResult.getPhone();
		// 根据手机号查询用户信息
		// VerificationCodeDTO verificationCodeDTO = new VerificationCodeDTO();
		// verificationCodeDTO.setPassengerPhone(phone);

		// Feign用RequestBody传输数据时，会将Get方法转换为Post
		ResponseResult user = servicePassengerUserClient.getUser(phone);
		// 将用户信息返回回去
		return ResponseResult.success(user);
	}
}
